﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Framework;

namespace NLBS.Data.Business
{
   public class CommonBase
    {
        protected static IList<string> GetKeyList(string key)
        {
            ContentCache cache = ContentCache.Instantiate();
            IList<string> lists = (List<string>)cache[key];
            if (lists == null)
            {
                lists = new List<string>();
                if (lists != null)
                {
                    cache.Insert(key, lists, CacheDuration.Long);
                }
            }
            return lists;
        }

        protected static void RemoveKeyList(string key)
        {
            ContentCache cache = ContentCache.Instantiate();
            IList<string> lists = CommonBase.GetKeyList(key);
            for (int i = 0; i < lists.Count; i++)
            {
                cache.Remove(lists[i]);
            }
            lists.Clear();
        }

        public static IList<T> GetCommonData<T>(string key, IList<T> list)
        {
            ContentCache cache = ContentCache.Instantiate();
            IList<T> lists = (List<T>)cache[key];
            if (lists == null)
            {
                lists = list;
                if (lists != null)
                {
                    cache.Insert(key, lists, CacheDuration.Long);
                    Cacher.GetArticleKey().Add(key);
                }
            }
           
            return lists;
        }

        public static ContentCache cache
        {
            get
            {
                return ContentCache.Instantiate();
            }
        }
    }
}
